package com.code.leetcode.offer;

import com.code.leetcode.utils.TreeNode;

/**
 * @author codeDorado
 * @version 1.0
 * @date 2020/8/4 10:24
 */
public class The54_B_逆序中序遍历 {

    int k, res;

    public int kthLargest(TreeNode root, int k) {
        this.k = k;
        dfs(root);
        return res;
    }

    private void dfs(TreeNode node) {
        if (node == null) return;
        dfs(node.right);
        if (k == 0) return;
        if (--k == 0) res = node.val;
        dfs(node.left);
    }

}
